package com.cmc.cloud.cmclink.doc.controller.admin.so;

import com.cmc.cloud.cmclink.doc.api.document.req.soamendapplyvo.SoAmendApplyPageReqVO;
import com.cmc.cloud.cmclink.doc.api.document.req.soamendapplyvo.SoAmendApplyRespVO;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.convert.SoAmendApplyConvert;
import com.cmc.cloud.cmclink.doc.entity.SoAmendApplyDO;
import com.cmc.cloud.cmclink.doc.service.so.SoAmendApplyService;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 订舱修改申请审批表主前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱修改申请审批表主")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/so-amend-apply")
public class SoAmendApplyController {

    @Resource
    private SoAmendApplyService soAmendApplyService;



    @Operation(summary = "获得订舱修改申请审批表主")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('doc:so-amend-apply:query')")
    public CommonResult<SoAmendApplyRespVO> getSoAmendApply(@PathVariable("id") Long id) {
        SoAmendApplyDO soAmendApply = soAmendApplyService.getSoAmendApply(id);
        return CommonResult.success(SoAmendApplyConvert.INSTANCE.convert(soAmendApply));
    }

    @Operation(summary = "获得订舱修改申请审批表主列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:so-amend-apply:query')")
    public CommonResult<List<SoAmendApplyRespVO>> getSoAmendApplyList(@RequestParam("ids") Collection<Long> ids) {
        List<SoAmendApplyDO> list = soAmendApplyService.getSoAmendApplyList(ids);
        return CommonResult.success(SoAmendApplyConvert.INSTANCE.convertList(list));
    }

    @Operation(summary = "获得订舱修改申请审批表主分页")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermission('doc:so-amend-apply:query')")
    public CommonResult<PageResult<SoAmendApplyRespVO>> getSoAmendApplyPage(@Valid SoAmendApplyPageReqVO pageVO) {
        PageResult<SoAmendApplyDO> pageResult = soAmendApplyService.getSoAmendApplyPage(pageVO);
        List<SoAmendApplyRespVO> results = SoAmendApplyConvert.INSTANCE.convertList(pageResult.getList());
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
